package online.learningsp.common.valid;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @author QiuYingMu
 * @create 2024-05-11 19:24
 */

@Slf4j
public class ParameterConstraintValidator implements ConstraintValidator<ParameterValid, Integer> {

    private String regexp = "";

    @Override
    public void initialize(ParameterValid constraintAnnotation) {
        regexp = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        Boolean isValid = false;
        isValid = integer.toString().matches(regexp);
        log.info("参数：{} -- 规则：{} -- 是否匹配：{}", integer, regexp, isValid);
        return isValid;
    }
}
